#include "../lib/node.hpp"
#include <boost/lexical_cast.hpp>

using namespace std;

Node::Node(std::string name)
{
    name_ = name;
}

void Node::addParrent(Node* parrent)
{
    parrents_.push_back(parrent);
}

void Node::addChild(Node* child)
{
    childeren_.push_back(child);
}

void Node::joinChild(Node* child)
{
    childeren_.push_back(child);
    child->addParrent(this);
}

void Node::joinParrent(Node* parrent)
{
    parrents_.push_back(parrent);
    parrent->addChild(this);
}

void Node::addProperty(std::string key, std::string value)
{
    properties_.insert(std::make_pair(key, value));
}

std::string Node::property(std::string key)
{
    if(properties_.find(key) == properties_.end())
        return "";
    else
        return properties_[key];
}

int Node::propertyAsInt(std::string key)
{
    string val = property(key);
    if(val == "")
        return 0;
    return boost::lexical_cast<int>(val);
}

std::map < std::string, std::string > Node::properties()
{
    return properties_;
}

void Node::setProperties(std::map < std::string, std::string > properties)
{
    properties_ = properties;
}
